package view.panel
{
	import control.panel.IPanelControl;
	import control.panel.PlayerItemPanelControl;
	
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import global.Resource;
	
	import model.hall.ListData;
	
	import utils.TextTool;
	
	import view.components.ImgButton;
	import view.components.Input;
	import view.components.LoadingBar;
	import view.components.RemoteHtmlImg;
	
	public class PlayerDiscribePanel extends AbsPanel
	{
		private var remoteImg:RemoteHtmlImg;
		private var traceBut:ImgButton;
		private var nameInput:TextField;
		private var moneyInput:Input;
		private var expBar:LoadingBar;
	
		private var levelInput:TextField;
		
		
		public function PlayerDiscribePanel(panelControl:IPanelControl)
		{
			super(panelControl);
			resetBg(230,108);
			initCloseBut();
			resetCloseBut();
			dropShadow();
			
			initRemoteImg();
			initText();
			initBut();
			initImg();
			
			
		}
		
		private function initImg():void
		{
			addChild(Resource.getImgXY(85,16,"face_gold"));
		}
		
		private function initBut():void
		{
			traceBut = new ImgButton(140,70,0,onTrace,60,20,"butBg",null,"追踪玩家");
			addChild(traceBut);
		}
		
		private function initText():void
		{
			moneyInput = new Input(99,19);
			moneyInput.x = 102;
			moneyInput.y = 16;
			addChild(moneyInput);
			
			levelInput = TextTool.getTextFieldXY(85,40,40,20,12,0xFFFFFF,"");
			addChild(levelInput);
			
			expBar = new LoadingBar("face_expFace","face_expBg");
			expBar.x = 120;
			expBar.y = 45;
			addChild(expBar);
			
			nameInput = TextTool.getTextFieldXY(20,66,100,20,12,0xFFFFFF,"");
			addChild(nameInput);
		}
		
		private function onTrace(event:MouseEvent):void
		{
			(panelControl as PlayerItemPanelControl).onTrace();	
			close();
		}
		
		private function initRemoteImg():void
		{
			remoteImg = new RemoteHtmlImg(50,50);
			remoteImg.x = 19;
			remoteImg.y = 16;
			addChild(remoteImg);
		}
		
		public function update(data:ListData):void
		{
			nameInput.text = data.userName;
			moneyInput.text = data.money;

			if (int(data.data.@nextExp) <= 0)
			{
				expBar.percent = 0;
			}
			else
			{
				expBar.percent = int(data.data.@exp) / int(data.data.@nextExp);
			}
			
			levelInput.text = data.data.@level + "级";
			remoteImg.loadImg(data.headImg);
			
			
			if (String(data.data.@state) ==  "2")//离线
			{
				traceBut.mouseEnabled = false;
			}
			else
			{
				traceBut.mouseEnabled = true;
			}
		}
		
		
	}
}